﻿package com.d4p.basicSetting
{
	import flash.display.LoaderInfo;
	import flash.display.Sprite;
	import flash.display.StageAlign;
	import flash.display.StageQuality;
	import flash.display.StageScaleMode;
	import flash.events.Event;
	import flash.system.Security;
	
	public class BasicDocument extends Sprite
	{
		protected function defaultSiteSet($frameRate:Number = 36,
										  $scaleAlign:String = DEFAULT_NOSCALE, 
										  $domainAllow:String = '*', 
										  $contextMenu:Boolean = false,
										  $stageQuality:String = BEST_QUALITY):void{
			
			///DOC setting.
			framteRates		= $frameRate;
			siteFrameSelect = $scaleAlign;
			domainAllow		= $domainAllow;
			contextMenuShow = $contextMenu;
			stageQuality	= $stageQuality;
		}
			
			
		
		//scale, align mode.
		public static const DEFAULT_NOSCALE:String 	= 'defaultNoScale';
		public static const DEFAULT_TOP:String 		= 'defaultTop';
		public static const SHOWALL_NOSCALE:String	= 'showallNoscale';
		
		
		//quality mode.
		public static const BEST_QUALITY:String		= 'bestQuality';
		public static const HIGH_QUALITY:String		= 'highQuality';
		public static const LOW_QUALITY:String		= 'lowQuality';
		public static const MEDIUM_QUALITY:String	= 'mediumQuality';
		
		
		protected function set framteRates($param:Number):void
		{
			stage.frameRate = $param;
		}
		
		/**
		 * 
		 * @param $param : scalemode, align mode.
		 * 
		 */		
		protected function set siteFrameSelect($param:String):void
		{
			switch($param){
				case DEFAULT_NOSCALE :
					stage.scaleMode = StageScaleMode.NO_SCALE;
					stage.align		= StageAlign.TOP_LEFT;
				break;
				case DEFAULT_TOP :
					stage.scaleMode = StageScaleMode.NO_SCALE;
					stage.align		= StageAlign.TOP;
				break;
				case SHOWALL_NOSCALE :
					stage.scaleMode = StageScaleMode.SHOW_ALL;
					stage.align		= StageAlign.TOP_LEFT;
				break;
			}
		}
		
		/**
		 * 
		 * @param $url : allowdomain.
		 * 
		 */		
		protected function set domainAllow($url:String):void
		{
			Security.allowDomain($url);
		}
		
		/**
		 * 
		 * @param $bool : contextMenu show.
		 * 
		 */		
		protected function set contextMenuShow($bool:Boolean):void
		{
			stage.showDefaultContextMenu	=	$bool;
		}
		
		/**
		 * 
		 * @param $param : stage quality.
		 * 
		 */		
		protected function set stageQuality($param:String):void
		{
			switch($param){
				case BEST_QUALITY :
					stage.quality = StageQuality.BEST;
				break;
				case HIGH_QUALITY :
					stage.quality = StageQuality.HIGH;
				break;
				case LOW_QUALITY :
					stage.quality = StageQuality.LOW;
				break;
				case MEDIUM_QUALITY :
					stage.quality = StageQuality.MEDIUM;
				break;
			};
		}
		
		
		/**
		 * is local. 
		 */		
		private var _isLocal:String;
		protected function get isLocal():String
		{
			return _isLocal;
		}
		protected function set isLocal($localUrl:String):void
		{
			if($localUrl.substr(0,4) == "file"){
				_isLocal = "FILE";
			}else{
				_isLocal = "URL";
			}
		}
		
		/**
		 *
		 *  flash vars.
		 *  
		 */		
		private var _flashVarsObj:Array;
		protected function get flashVarsObj():Array
		{
			return _flashVarsObj;
		}
		protected function flashVars($param:Object, $paramName:String):void
		{
			$param = LoaderInfo(this.root.loaderInfo).parameters;
			
			_flashVarsObj.push($param[$paramName]);
		}
		
		
		public function BasicDocument()	{}
	}
}